package com.tomryan.TLabel.controller;

import com.tomryan.TLabel.config.SystemConfig;
import com.tomryan.TLabel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tomryan.TLabel.model.User;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by TangRunQing on 2018/01/30.
 */
@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping(value = "login")
    @ResponseBody
    public String login(@RequestParam String userName, @RequestParam String passWord, Model model, HttpSession session) {
        String validResult = "";
        User systemUser = userService.validLogin(userName, passWord);
        if (systemUser != null) {
            session.removeAttribute(SystemConfig.SUPERUSERSESSION);
            session.setAttribute(SystemConfig.SUPERUSERSESSION, systemUser.getUserid());
            validResult = "T";
        } else {
            validResult = "F";
        }
        return validResult;
    }
}
